<link type="text/css" href="/admins/js/pagerView/pager-view.css" rel="stylesheet" />
<link type="text/css" href="/admins/js/jquery/css/ui-lightness/jquery-ui-1.8.20.custom.css" rel="stylesheet" />
<script type="text/javascript" src="/admins/js/jquery/jquery-ui-1.8.20.custom.min.js"></script>
<script type="text/javascript" src="/admins/js/jquery/jquery.ui.datepicker-zh-CN.js"></script>
<script type="text/javascript" src="/admins/js/pagerView/pager-view.js"></script>
<script type="text/javascript">
$(function(){
	$.datepicker.setDefaults( $.datepicker.regional[ "zh-CN" ] );
	$( "#del-button").button().click( function () {
		if (confirm( "你真的要删除选中的订单吗？" )) {
			idList = "";
			sp = "";
			$( ".checkbox-del" ).each(function(){
				if ($(this).attr("checked") == "checked") {
					idList += sp + $(this).val();
					if (sp == "") sp = ",";
				}
			});
			$.ajax({
				type: "POST",
				url: "/admin/order/warehouse-del",
				dataType: "json",
				data:"idList="+idList,
				success: function(data) {
					var result=eval(data);
					if (result == true) {
						$( "#queryButton").click();
						alert( "删除成功！" );
					} else {
						alert( "删除失败！" );
					}
				}
			});
		}
	});
    $( "#queryButton").button().click( function () {
		$("#starttime2").val($("#starttime").val());$("#endtime2").val($("#endtime").val());
		$("#productName2").val($("#productName").val());$("#username2").val($("#username").val());
		$("#state2").val($("#state").val());
	    $.ajax({
			type: "POST",
			url: "/admin/order/warehouse-query",
			dataType: "json",
			data:"starttime="+$("#starttime").val()+"&endtime="+$("#endtime").val()+"&productName="+$("#productName").val()+"&username="+$("#username").val()+"&state="+$("#state").val()+"&pagesize="+pager.size,
			success: function(data) {
				var items=eval(data.items);
				bindDataTable(items)
				pager.itemCount = data.count;
				pager.index = 1
				pager.render();
			}
		});

		return false; 
	});
	$( "#starttime" ).datepicker();
	$( "#endtime" ).datepicker();
	var pager = new PagerView('pager');
	pager.size = 15; // 每页显示15条记录
	pager.maxButtons = 10;
	pager.itemCount = 0;
	pager.onclick = function(index) {
		$.ajax({
			type: "POST",
			url: "/admin/order/warehouse-pager",
			dataType: "json",
			data:"starttime="+$("#starttime2").val()+"&endtime="+$("#endtime2").val()+"&productName="+$("#productName2").val()+"&username="+$("#username2").val()+"&state="+$("#state2").val()+"&pagesize="+pager.size+"&pageindex="+index,
			success: function(data) {
				var items=eval(data);
				bindDataTable(items)
			}
		});
		
	};
	pager.render();

	$( "#queryButton").click();
});
function bindDataTable(items) {
	$(".datatable tbody").empty();
	$.each(items, function(k)
	{
		switch (items[k]['state']) {
		    case '0':
			    items[k]['state'] = '未入库';
				break;
			case '1':
			    items[k]['state'] = '已入库';
				break;
			case '2':
			    items[k]['state'] = '已出库';
				break;
			default:
			    items[k]['state'] = '未知';
				break;
		} 
		$(".datatable tbody").append("<tr><td><input type=\"checkbox\" value=\""+items[k]['id']+"\" class=\"checkbox-del\" /></td><td>"+items[k]['id']+"</td><td>"+items[k]['username']+"</td><td>"+items[k]['productName']+"</td><td>"+items[k]['state']+"</td><td>"+items[k]['storeId']+"</td><td>"+items[k]['dateInStore']+"</td><td>"+items[k]['price']+"</td><td>"+items[k]['quantity']+"</td><td>"+items[k]['weight']+"</td><td>"+items[k]['orderNo']+"</td><td>"+items[k]['Logistics']+"</td><td>"+items[k]['dateOut']+"</td><td><img src=\"/admins/images/edit.gif\" id=\""+items[k]['id']+"\" class=\"edit-operation\"/></td></tr>");
	});
	$( ".edit-operation").click( function () {
		showDialog(this.id);
	});
	$( ".datatable tbody tr" ).each(function(){
		$(this).click( function () { 
			$( ".datatable .select" ).removeClass("select");
			$(this).addClass("select"); 
		});
		$(this).hover(
			function () {
				$(this).addClass("hover");
			},
			function () {
				$(this).removeClass("hover");
			}
		);
	});
}
</script>
<form action="/admin/order/warehouse" method="post" style="margin:0px">
<div style=" border:1px solid #DDDDDD; padding:2px; margin:2px;">
<label for="starttime">订单时间：</label><input type="text" id="starttime" name="starttime" />
<label for="endtime">--</label><input type="text" id="endtime" name="endtime" />
<label for="commodity">商品：</label><input type="text" id="productName" name="productName" />
<label for="member">用户：</label><input type="text" id="username" name="username" />
<label for="state">状态：</label>
<select id="state" name="state">
  <option value="">全部</option>
  <option value="1">待处理</option>
  <option value="2">已处理</option>
</select>
<input type="submit" id="queryButton" value="查询"/>
</div>
</form>
<style>
	.datatable {
		text-align: left;
		font-size: 12px;
		font-family: verdana;
		background: #c0c0c0; margin:2px;
	}

	.datatable thead tr,

	.datatable tfoot tr {
		background: #c0c0c0;
	}

	.datatable tbody tr {
		background: #f0f0f0;
	}

	.datatable td, th {
		border: 1px solid white; height:28px;
	}
	.datatable td {background-color:white;}
	
	.datatable .hover td {background-color:#99CCFF;}
	
	.datatable .select td {background-color:#EEEE99;}

	#ui-datepicker-div{ font-size:12px;}
</style>
<div style="padding:2px; margin:2px;">
<table cellspacing="1" width="100%" class="datatable">
	<thead>
		<tr>
            <th></th>
			<th>ID</th>
			<th>用户</th>
			<th>商品名称</th>
			<th>状态</th>
			<th>仓库单号</th>
			<th>入库时间</th>
			<th>单价</th>
            <th>数量</th>
            <th>重量</th>
            <th>订单号</th>
			<th>快递单号</th>
			<th>出库时间</th>
            <th>操作</th>
		</tr>
	</thead>
    <tfoot>
      <tr><td colspan="14"><button id="del-button">删除选中</button></td></tr>
    </tfoot>
	<tbody>
	</tbody>
</table>
</div>
<form action="/admin/order/warehouse-pager" method="post">
<input type="hidden" id="starttime2" name="starttime2" value="" />
<input type="hidden" id="endtime2" name="endtime2" value="" />
<input type="hidden" id="productName2" name="productName2" value="" />
<input type="hidden" id="username2" name="username2" value="" />
<input type="hidden" id="state2" name="state2" value="" />
</form>
<div id="pager" class="pager"></div>
<style type="text/css">
#dialog-modal { display:none; }
#dialog-modal input { width:170px;}
</style>
<script type="text/javascript">
$(function(){
	$( "#dialog:ui-dialog" ).dialog( "destroy" );
	$( "#dialog-modal" ).dialog({
		height: 300,
		width: 800,
		modal: true,
		autoOpen: false
	});
    $( "#edit-button-ok").button().click( function () {
		id = $("#record-id").val();productName = $("#product-name").val();state = $("#store-state").val();
		stateName = document.getElementById('store-state').options[document.getElementById('store-state').selectedIndex].text;
		storeId_value = $("#storeId").val();intype_value = $("#intype").val();createdate_value = $("#createdate").val();
		price_value = $("#price").val();quantity_value = $("#quantity").val();weight_value = $("#weight").val();
		dateInStore_value = $("#dateInStore").val();remark_value = $("#remark").val();orderNo_value = $("#orderNo").val();
		productId_value = $("#productId").val();logistics_value = $("#logistics").val();
		$.ajax({
			type: "POST",
			url: "/admin/order/warehouse-edit",
			dataType: "json",
			data:"id="+id+"&productName="+productName+"&state="+state+"&storeId="+storeId_value+"&intype="+intype_value+"&createdate="+createdate_value+"&price="+price_value+"&quantity="+quantity_value+"&weight="+weight_value+"&dateInStore="+dateInStore_value+"&remark="+remark_value+"&orderNo="+orderNo_value+"&productId="+productId_value+"&logistics="+logistics_value,
			success: function(data) {
				var result=eval(data);
				if (result == true) {
					alert( "更新成功！" );
					row = $( ".datatable .select" ).children();
					$(row).eq(3).text(productName);
					$(row).eq(4).text(stateName);
					$(row).eq(5).text(storeId_value);
					$(row).eq(6).text(dateInStore_value);
					$(row).eq(7).text(price_value);
					$(row).eq(8).text(quantity_value);
					$(row).eq(9).text(weight_value);
					$(row).eq(10).text(orderNo_value);
					$(row).eq(12).text(createdate_value);
					$( "#dialog-modal" ).dialog( "close" );
				} else {
					alert( "更新失败！" );
				}
			}
		});
	});
	$( "#edit-button-cancel").button().click( function () {
		$( "#dialog-modal" ).dialog( "close" );
	});
});
function showDialog(id) {
	$.ajax({
		type: "POST",
		url: "/admin/order/warehouse-details",
		dataType: "json",
		data:"id="+id,
		success: function(data) {
			var object=eval(data);
			if (object != false) {
			    $("#record-id").val( object.id );
				$("#product-name").val( object.productName );
				$("#store-state").val( object.state );
				$("#storeId").val( object.storeId );
				$("#intype").val( object.intype );
				$("#createdate").val( object.createdate );
				$("#price").val( object.price );
				$("#quantity").val( object.quantity );
				$("#dateInStore").val( object.dateInStore );
				$("#weight").val( object.weight );
				$("#remark").val( object.remark );
				$("#orderNo").val( object.orderNo );
				$("#productId").val( object.productId );
				$("#logistics").val( object.Logistics );
				$( "#dialog-modal" ).dialog( "open" );
			} else {
				alert( "获取数据失败！" );
			}
		}
	});
}
</script>
<div id="dialog-modal" title="操作">
	<table width="100%">
      <tr>
        <td align="right" width="100">名称：</td><td colspan="3"><input id="product-name" type="text" value="" style="width:99%;" /></td>
		<td align="right">状态：</td>
		<td>
			<select id="store-state">
			  <option value="1">待处理</option>
			  <option value="2">已处理</option>
			</select>
		</td>
      </tr>
      <tr>        
        <td align="right">仓库单号：</td><td><input id="storeId" type="text" value="" /></td>
		<td width="100" align="right">类型：</td><td><input id="intype" type="text" value="" /></td>
		<td width="100" align="right">提交时间：</td><td><input id="createdate" type="text" value="" /></td>
     </tr>
     <tr>
        <td align="right">单价：</td><td><input id="price" type="text" value="" /></td>
		<td align="right">数量：</td><td><input id="quantity" type="text" value="" /></td>
		<td align="right">入库时间：</td><td><input id="dateInStore" type="text" value="" /></td>
     </tr>
     <tr>
        <td align="right">重量：</td><td><input id="weight" type="text" value="" /></td>
		<td align="right">物流公司：</td><td><input id="logistics" type="text" value="" /></td>
		<td align="right">快递单号：</td><td><input id="" type="text" value="" /></td>
     </tr>
     <tr>
        <td align="right">商品备注：</td><td colspan="5"><textarea id="remark" rows="3" style="width:99%"></textarea></td>
     </tr>
     <tr>
        <td align="right">关联订单：</td><td><input id="orderNo" type="text" value="" /></td>
		<td align="right">关联产品：</td><td><input id="productId" type="text" value="" /></td>
		<td align="right">关联运单：</td><td><input id="" type="text" value="" /></td>
     </tr>
     <tr>
       <td colspan="6" align="center">
       <button id="edit-button-ok">确认更新</button>
       <button id="edit-button-cancel">取消返回</button><input type="hidden" id="record-id" value="" />
       </td>
     </tr>
    </table>
</div>